package com.sgb.kjwl.view.ui.adapter.self.mine;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.CompanyFocusEntity;
import com.sgb.kjwl.view.ui.activity.manage.ShopInfoForCompanyTradesActivity;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter3;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

public class CompanyFocusAdapter extends BaseRecycleAdapter3<CompanyFocusEntity> {

    private OnItemClickFocus clickFocus;
    public CompanyFocusAdapter(Context context, List<CompanyFocusEntity> datas,OnItemClickFocus itemClickFocus) {
        super(context, R.layout.item_company_focus, datas);
        this.clickFocus = itemClickFocus;
    }

    @Override
    public void convert(ItemViewHolder holder, CompanyFocusEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView focusStatus = holder.getItem().findViewById(R.id.focusState);
        RelativeLayout relativeLayout = holder.getItem().findViewById(R.id.root_layout);
        ImageView logo = holder.getItem().findViewById(R.id.company_logo);
        if (entity.isCompanyFocus()){
            focusStatus.setText("已关注");
            focusStatus.setTextColor(holder.getItem().getContext().getResources().getColor(R.color.color_tab_three));
            focusStatus.setBackgroundResource(R.drawable.shpae_rd5_str1_grey_bg);
            //focusStatus.setCompoundDrawablesRelativeWithIntrinsicBounds(holder.getItem().getContext().getResources().getDrawable(R.drawable.icon_focus),null,null,null);
        } else {
            focusStatus.setText("关注");
            focusStatus.setTextColor(holder.getItem().getContext().getResources().getColor(R.color.color_main));
            focusStatus.setBackgroundResource(R.drawable.shape_rd5_str1_red_bg);
            //focusStatus.setCompoundDrawablesRelativeWithIntrinsicBounds(holder.getItem().getContext().getResources().getDrawable(R.drawable.icon_no_focus),null,null,null);
        }
        focusStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickFocus.OnClickItem(holder.getPosition()-1);
            }
        });
        relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(context, ShopInfoForCompanyTradesActivity.class);
//                if (entity.getCompanyId() != null) {
//                    intent.putExtra("id", entity.getCompanyId());
//                    intent.putExtra("companyNo", entity.getCompanyNo());
//                    intent.putExtra("position", 5);
//                    context.startActivity(intent);
//                } else {
//                    MToast.showToast(context, "店铺id为空");
//                }
                if (!TextUtils.isEmpty(entity.getCompanyNo())){
                    WebsiteInfoActivity.start(context, entity.getCompanyNo(), WebsiteInfoActivity.WEBSITE_FOR_COMPANY);
                }
            }
        });
    }

    public interface OnItemClickFocus{
        void OnClickItem(int position);
    }

}
